import React from 'react';
import Table, {
    setColumnKeys,
    yesRender
} from '../_/table';
import redux from '../_/redux';
import _name, {_title} from './dev';

@redux(_name, ['load', 'del', 'modify'])
export default class Table1 extends React.Component {
    render() {
        const {data = []} = this.props;
        const treeData = data;//getTree();
        const columns = [{
            title: `${_title}名称`,
            dataIndex: 'Name'
        }, {
            title: '检索码',
            dataIndex: 'NameJp'
        }, {
            title: '注释',
            dataIndex: 'Comment'
        }, {
            title: '状态',
            dataIndex: 'Status',
            render: yesRender
        }, {
            title: '操作',
            render: (val, data) => (
                <span>
                    <a className="blue" onClick={() => this.props.onState('edit', data)}>编辑</a>
                    <span className="ant-divider"/>
                    {/*<Popconfirm*/}
                    {/*title="确定要删除当前记录吗"*/}
                    {/*onConfirm={() => this.props.del(data, this.props)}*/}
                    {/*okText="确定" cancelText="取消"*/}
                    {/*>*/}
                    {/*<a className="red">删除</a>*/}
                    {/*</Popconfirm>*/}
                    {/*<span className="ant-divider"/>*/}
                    <a
                        className={data.Status ? "red" : "green"}
                        onClick={() => this.props.modify({
                            ...data,
                            Status: data.Status ? 0 : 1
                        })}
                    >
                        {data.Status ? '停用' : '启用'}
                    </a>
                </span>
            )
        }];
        setColumnKeys(columns);
        return (
            <div className="w100 padding-t">
                <Table
                    pagination={false}
                    columns={columns}
                    dataSource={treeData}
                    {...this.props}
                />
            </div>
        )
            ;
    }
}
